<template>
  <div class="content_box">
    <div class="lanmu_box">
      <div class="box">
        <van-tabs v-model="active" @change="tabChange">
          <van-tab :title="item.name" v-for="(item,index) in lanmu" :key="index"></van-tab>
        </van-tabs>
      </div>
    </div>
    <div class="coupon-item" v-if="cardList.length">
      <div class="box" v-for="(item,index) in cardList" :key="index" @click="toCardDetail(item.id)">
        <img class="bj" src="/static/images/coupon_bj.png" alt="">
        <p class="label" >限时折扣</p>
        <div class="nr">
          <div class="left">
            <p class="price"><span>￥</span>{{item.sellPrice}}</p>
           
          </div>
          <p class="line"></p>
          <div class="right">
            <div class="name_box">
              <div class="name">
                <p class="title" >{{ item.name }}* {{ item.bindNum }}张</p>
                <p class="time">有效期天数：{{item.validDay}}</p>
                <p class="text">剩余:{{item.stock}}份</p>
              </div>
              <p class="anniu" v-if="item.stock"   >去购买</p>
              <p class="anniu disable" v-else >已抢光</p>
            </div>
            <p class="jiesao">{{item.remark}}</p>
          </div>
        </div>
      </div>

      <!-- <div class="item" v-for="(item, index) in cardList" :key="index" @click="toCardDetail(item.id)">
        <div class="left">
          <p class="name">{{ item.name }}</p>
          <p class="text">有效天数：{{ item.validDay }}天</p>
        </div>
        <div class="right">
          <p class="price">￥<span>{{ item.sellPrice }}</span></p>
          <p class="anniu">购买</p>
        </div>
      </div> -->
    </div>
    <div class="no_data" v-else>
     <img mode="widthFix" src="/static/images/components/no_order.png" alt="" />
      <!-- <p class="text"></p> -->
   </div>
  </div>
</template>

<script>
import {
  getCardCouponPage
} from "@/api/index";
export default {
  data() {
    return {
      lanmu:[
       {name:'台球卡券',query:0},
       {name:'麻将卡券',query:1}
     ],
     lanmuIndex:0,
     cardList:[],
     query: {
        current: 1,
        size: 10,
        cardType:1,
        cardCouponIlk: 0
     }
    };
  },
  onReachBottom(){
   //console.log('到底了')
   this.query.current += 1
   this.getCardList()
 },
  methods: {

    tabChange(e){
      //console.log(e)
      this.lanmuIndex=e.mp.detail.index
      this.query.current = 1
      this.cardList=[]
      this.query.cardCouponIlk=this.lanmu[this.lanmuIndex].query
     
      this.getCardList()
    },

    toCardDetail(id){
      wx.navigateTo({
        url: `/pages/card_detail/main?id=${id}`,
      });
    },

    // 卡券列表
    async getCardList() {
      const res = await getCardCouponPage(this.query)
      if (res.statusCode === '00000' ) {
        if(this.query.current != 1 && !res.data.records.length){
          this.query.current =this.query.current  - 1
            wx.showToast({
              title: '已经到底了~',
              icon: 'none',
              duration: 1500
            })
            return
          }
        this.cardList = this.cardList.concat(res.data.records)
        // debugger
      }
    }
  },
  onLoad(options){
    this.query.cardCouponIlk = 0
    this.cardList=[]
    this.getCardList()
  },
  onShow() {
  },
};
</script>

<style lang="scss" scoped>
.content_box{
  width: 100%;
  min-height: 100vh;
  background: #F5F5F5;
  .lanmu_box{
    height: 88rpx;
    margin-bottom:24rpx;
    .box{
      position: fixed;
      top:0;
      width: 100%;
      z-index: 100;
      background: #fff;
    }
    /deep/ .van-tab{
      color:#666666;
      font-size:30rpx;
    }
    /deep/ .van-tabs__line{
      background: #00C200;
    }
    /deep/ .van-tab--active{
      color:#00C200;
      font-weight: bold;
    }
  }
  .coupon-item {
    padding-top: 24rpx;
    .box{
      width: 92%;
      height: 208rpx;
      position: relative;
      margin:0 auto;
      margin-bottom:24rpx;
      .bj{
        width: 100%;
        height: 100%;
        position: absolute;
        top:0;
        left:0;
        z-index: 10;
      }
      .bj1{
        width: 100%;
        height: 100%;
        position: absolute;
        top:15rpx;
        left:0;
        z-index: 1;
      }
      .label{
        position: absolute;
        top:0;
        left: 6rpx ;
        padding:0 16rpx;
        height: 40rpx;
        background: linear-gradient(to right,#FF4357, #FE6E34);
        z-index: 20;
        font-size:22rpx;
        color:#fff;
        display: flex;
        align-items: center;
        justify-content: center;
        border-top-left-radius: 16rpx;
        border-bottom-right-radius: 16rpx;
        font-weight: 500;
      }
      .nr{
        position: relative;
        z-index: 30;
        display: flex;
        .left{
          width: 29%;
          height: 208rpx;
          display: flex;
          flex-direction:column;
          justify-content: center;
          align-items: center;
          .price{
            display: flex;
            align-items: baseline;
            font-size:60rpx;
            font-weight: bold;
            color:#FF4622;
            span{
              font-size:30rpx;
            }
          }
         
        }  
        .line{
          width: 1rpx;
          height: 160rpx;
          border-right:1px dashed #E4E4E4;
          margin-top:22rpx;
        }
        .right{
          width: 600rpx;
          padding-left:24rpx;
          .name_box{
            display: flex;
            justify-content: space-between;
            align-items: flex-end;
            margin-top:40rpx;
            margin-bottom:28rpx;
            .name{
              padding-top: 10px;
              .title{
                color:#242526;
                font-size:32rpx;
                font-weight: 500;
                margin-bottom:12rpx;
                
              }
              .time{
                color:#666666;
                font-size:24rpx;
              }
              .text{
                font-size:24rpx;
            color:#FF4622;
            margin-top: 5px;
            position: absolute;
            top: 20px;
            right: 15px;
          }
            }
            img{
              width: 124rpx;
              height: 124rpx;
              position: absolute;
              right: 6rpx;
              top:8rpx;
            }
            .anniu{
              width: 114rpx;
              height: 50rpx;
              background: linear-gradient(to right,#FF4357, #FE6E34);
              font-size:24rpx;
              color:#fff;
              font-weight: bold;
              border-radius: 50rpx;
              display: flex;
              align-items: center;
              justify-content: center;
              margin-right:22rpx;
            }
            .disable{
              background: rgba(0, 0, 0, .3);
            }
          }
          .jiesao{
            color:#999999;
            font-size:22rpx;
          }
        }      
      }
      &.on{
        .label{
          color:#383838;
          background: #F6F6F8 ;
        }
        .price{
          color:#AEAFB0 !important;
        }
        .text{
          color:#B0B1B4 !important ;
        }
        .title{
          color:#8D8E90 !important;
        }
        .time{
          color:#AEAFB0 !important ;
        }
        .jiesao{
          color:#C8C8CA !important;
        }
      }
    }
  }
  .no_data{
   text-align: center;
   font-size:28rpx;
   color:#333;
   padding-top:150rpx;
   .text{
     font-weight: bold;
     color:#999;
   }
   img{
     width: 248rpx;
     margin-bottom:10rpx;
   }
   .button{
     width: 240rpx;
     height: 70rpx;
     line-height: 70rpx;
      background: #02b4ae;
     // background: #35c982;
     border-radius: 120rpx;
     text-align: center;
     font-size: 30rpx;
     color: #fff;
     margin-top: 30rpx;
     margin: 30rpx auto 0 auto;
   }
 }
}
</style>